﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class Watcher
{
    public static void Run()
    {
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = @"C:\SomeFolder";

        watcher.NotifyFilter = NotifyFilters.LastWrite;
        watcher.Filter = "have.txt";

        watcher.Changed += new FileSystemEventHandler(OnChange);

        watcher.EnableRaisingEvents = true;

        Console.WriteLine("Press \'q\' to quit the sample.");
        while (Console.Read() != 'q')
        { }
    }

    private static void OnChange(Object source, FileSystemEventArgs e)
    {
        //FileStream stream = new FileStream(@"C:\SomeFolder\have.txt", FileMode.Open, FileAccess.Read);
        //using (stream)
        //{
        //    StreamReader reader = new StreamReader(stream);
        //    using (reader)
        //    {
        //        string data = reader.ReadToEnd();
        //        Console.WriteLine(data);
        //    }
        //}
        Console.WriteLine("The File Has Been Changed");
    }

    static void Main()
    {
        Run();
    }
}
